package com.hh.bss.project.controller;

import static com.hh.bss.util.extjs.JsonHelper.outJson;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JsonConfig;

import org.springframework.stereotype.Controller;

import com.hh.bss.auth.client.OnlineManager;
import com.hh.bss.auth.client.OnlineUser;
import com.hh.bss.base.BaseSpringController;
import com.hh.bss.common.cache.DynaBusinessCache;
import com.hh.bss.common.page.Page;
import com.hh.bss.common.page.PageRequest;
import com.hh.bss.project.entity.SearchProject;
import com.hh.bss.project.service.PlanService;
import com.hh.bss.project.service.ProjectService;
import com.hh.bss.project.vo.query.ProjectQuery;
import com.hh.bss.project.vo.query.SearchProjectQuery;
import com.hh.bss.util.extjs.ExtJsPageHelper;
import com.hh.bss.util.extjs.JsonHelper;
import com.hh.bss.util.extjs.ListRange;

@Controller
public class ProjectController extends BaseSpringController {

	private ProjectService projectService;
	protected static final String DEFAULT_SORT_COLUMNS = null; 
	/** 通过spring自动注入 */
	public void setProjectServiceImpl(ProjectService service) {
		this.projectService = service;
	}	
	public void list(HttpServletRequest request,HttpServletResponse response,ProjectQuery projectQuery) throws IOException
	{
		OnlineManager onlineManager=super.getOnlineManager(request, response);
		if (onlineManager!=null){
				OnlineUser onlineUser=onlineManager.getOnlineUser();
				if (onlineUser!=null) {
					projectQuery.setOnlineUser(onlineUser);
				}
			}
		PageRequest<Map> pr = ExtJsPageHelper.createPageRequestForExtJs(request, DEFAULT_SORT_COLUMNS);
		Page page = projectService.findProjectPage(projectQuery);
		
		List<SearchProject> SearchProjectlist = (List) page.getResult();
		ListRange<SearchProject> resultList = new ListRange<SearchProject>();
		resultList.setRows(SearchProjectlist);
		resultList.setTotal(page.getTotalCount());
		resultList.setMessage("ok");
		resultList.setSuccess(true);
		outJson(response,resultList);
		
	}
	public void businesslist(HttpServletRequest request,HttpServletResponse response) throws IOException
	{
		//
		//List l=DynaBusinessCache.getInfo();
		
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("data", DynaBusinessCache.getInfo());
		result.put("success", true);
		result.put("msg", "成功!");
		outJson(response,result);
//		JsonConfig jsonConfig = new JsonConfig();    
//		JsonHelper.outJsonString(response,JSONArray.fromObject(l,jsonConfig).toString()); 
		
	}
}
